package cn.harry.modular.sms.service.impl;

import cn.harry.common.exception.ApiException;
import cn.harry.modular.sms.exception.enums.SmsExceptionEnum;
import cn.harry.common.utils.BeanUtils;
import cn.harry.modular.sms.mapper.SysSmsTemplateMapper;
import cn.harry.modular.sms.domain.SysSmsTemplate;
import cn.harry.modular.sms.service.SysSmsTemplateService;
import cn.harry.modular.sms.vo.SmsTemplateDto;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 短信模板
 *
 * @author honghh Date 2019-10-12 10:55:44 Copyright (C) www.tech-harry.cn
 */
@Service
public class SysSmsTemplateServiceImpl
		extends ServiceImpl<SysSmsTemplateMapper, SysSmsTemplate>
		implements SysSmsTemplateService {

	@Override
	public SmsTemplateDto geSmsTemplateByCode(Long code) {
		if (code == null) {
			throw new ApiException(SmsExceptionEnum.MSG_TYPE_ERROR);
		}

		SysSmsTemplate smsTemplate = this.baseMapper
				.selectOne(new LambdaQueryWrapper<SysSmsTemplate>()
						.eq(SysSmsTemplate::getValue, code));

		return BeanUtils.transform(SmsTemplateDto.class, smsTemplate);
	}

}